var t = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (t) {
  return typeof t;
} : function (t) {
  return t && "function" == typeof Symbol && t.constructor === Symbol && t !== Symbol.prototype ? "symbol" : typeof t;
}, e = "function" == typeof Symbol && "symbol" == t(Symbol.iterator) ? function (e) {
  return void 0 === e ? "undefined" : t(e);
} : function (e) {
  return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : void 0 === e ? "undefined" : t(e);
}, n = require("jquery");

module.exports = {
  getUrl: function (param) {
    var a = getApp().getConfig().zhiboapi;
    return a + param;
  },
  json: function (t, e, o, i, a, r) {
    var s = getApp(), c = s.getCache("userinfo_openid"), u = s.getCache("usermid"), f = s.getCache("authkey");
    (e = e || {}).comefrom = "wxapp", e.openid = "sns_wa_" + c, u && (e.mid = u.mid,
      e.merchid = e.merchid || u.merchid);
    var d = this;
    i && d.loading(), e && (e.authkey = f || "");
    var l = {
      url: (a ? this.getUrl(t) : this.getUrl(t)) + "&timestamp=" + +new Date(),
      method: a ? "POST" : "GET",
      header: {
        "Content-type": a ? "application/x-www-form-urlencoded" : "application/json",
        Cookie: "PHPSESSID=" + c
      }
    };
    r || delete l.header.Cookie, a && (l.data = n.param(e)), o && (l.success = function (t) {
      if (i && d.hideLoading(), "request:ok" == t.errMsg && "function" == typeof o) {
        if (s.setCache("authkey", t.data.authkey || ""), void 0 !== t.data.sysset) {
          if (1 == t.data.sysset.isclose) return void wx.redirectTo({
            url: "/pages/message/auth/index?close=1&text=" + t.data.sysset.closetext
          });
          s.setCache("sysset", t.data.sysset);
        }
        o(t.data);
      }
    }), l.fail = function (t) {
      i && d.hideLoading(), d.alert(t.errMsg);
    }, wx.request(l);
  },
  post: function (t, e, n, o, i) {
    this.json(t, e, n, o, !0, i);
  },
  get: function (t, e, n, o, i) {
    console.log('--------------');
    console.log(t);
    this.json(t, e, n, o, !1, i);
  },
}